﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Silvermoon.Core
{
    /// <summary>
    /// used for scrolling.
    /// </summary>
    internal struct ScrollData
    {
        private float dx;
        private float dy;
        private float x;
        private float y;

        public int X { get { return (int)x; } }
        public int Y { get { return (int)y; } }

        private float accel;
        private int lastTick;

        public bool IsRunning { get; private set; }

        public void Reset(int x, int y, float dx, float dy)
        {
            this.dx = dx;
            this.dy = dy;
            this.x = x;
            this.y = y;
            accel = 1f;
            lastTick = Environment.TickCount;
        }

        public bool Step()
        {
            int tick = Environment.TickCount;
            float ms = (float)(tick - lastTick);
            lastTick = tick;
            x += dx * ms;
            y += dy * ms;
            dx *= accel;
            dy *= accel;
            accel -= 0.001f;
            if (accel <= 0f || (Math.Abs(dx) <= 0.005f && Math.Abs(dy) <= 0.005f))
            {
                accel = 0f;
                return false;
            }
            return true;
        }
    }
}
